The following program illustrates how to use an artificial regression of the residuals on the gradients to check for convergence of the non-linear least squares estimates.
'uses of gradients'checking NLS estimates by an artificial regression'see Davidson-MacKinnon 1993, chapter 6 'change path to program path%path = @runpathcd %path 'import data file amsta.dat as a workfile into EViews 'names varibles as t y x1 x2 & x3 wfload(page=gallant1) amstat.dat names=(t y x1 x2 x3) 'starting valuesc(1) = -0.04866c(2) = 1.03884c(3) = -0.73792c(4) = -0.51362 'replicate Gallant (1987) fig 5a (p.35)equation eq1.ls(c=1e-9,m=1000,showopts,deriv=aa) y = c(1)*x1 + c(2)*x2 + c(4)*exp(c(3)*x3)show eq1.output 'get residualseq1.makeresid res 'get derivative serieseq1.makederivs(n=grd1) 'run Gauss-Newton regression'all coefs, t-stats, and R2 should be within convergence 'tolerance if NLS convergedequation eq2.ls res grd1show eq2.output
The following program computes a Lagrange multiplier test statistic for an omitted variable (@trend) in a nonlinear regression model. See Davidson and MacKinnon (1993), Estimation and Inference in Econometrics, Chapter 6 for theoretical background.
'uses of gradients'LM test for omitted variable in NLS'see Davidson-MacKinnon 1993, chapter 6 'change path to program path%path = @runpathcd %path 'import data file amsta.dat as a workfile into EViews 'names varibles as t y x1 x2 & x3 wfload(page=gallant1) amstat.dat names=(t y x1 x2 x3) 'starting valuesc(1) = -0.04866c(2) = 1.03884c(3) = -0.73792c(4) = -0.51362 'estimate restricted model 'replicate Gallant (1987) fig 5a (p.35)equation eq1.ls(c=1e-9,m=1000,showopts,deriv=aa) y = c(1)*x1 + c(2)*x2 + c(4)*exp(c(3)*x3)show eq1.output 'get residualseq1.makeresid res 'get derivative serieseq1.makederivs(n=grd1) 'run Gauss-Newton regression (6.17)equation eq2.ls res @trend grd1 show eq2.output 'compute test statistic as n*R^2_uscalar lmstat = eq2.@regobs * (1 - eq2.@ssr/@sumsq(res)) 'show results in tabletable outout(1,1) = "Omitted variable test based on Gauss-Newton regression:"out(2,1) = "n*R^2_u = "out(2,2) = lmstatout(2,3) = "p-value = "out(2,4) = 1 - @cchisq(lmstat,1) 't-statistic in test regression!tstat = eq2.@tstats(1)'degrees of freedom!df = eq2.@regobs - eq2.@ncoefout(3,1) = "t-stat = "out(3,2) = !tstatout(3,3) = "p-value = "out(3,4) = 2*(1-@ctdist(@abs(!tstat),!df))show out
The following program computes a Lagrange multiplier test statistic for an omitted variable (@trend) in a nonlinear regression model. The test statistic is designed to be robust to heteroskedasticity of unknown form. See Davidson and MacKinnon (1993), Estimation and Inference in Econometrics, Chapter 6 for theoretical background.
'uses of gradients'hetero-robust Gauss-Newton regression'see Davidson-MacKinnon 1993, chapter 11.6 'change path to program path%path = @runpathcd %path 'import data file amsta.dat as a workfile into EViews 'names varibles as t y x1 x2 & x3 wfload(page=gallant1) amstat.dat names=(t y x1 x2 x3) 'starting valuesc(1) = -0.04866c(2) = 1.03884c(3) = -0.73792c(4) = -0.51362 'estimate restricted model 'replicate Gallant (1987) fig 5a (p.35)equation eq1.ls(c=1e-9,m=1000,showopts,deriv=aa) y = c(1)*x1 + c(2)*x2 + c(4)*exp(c(3)*x3)show eq1.output 'get residualseq1.makeresid res 'get derivative serieseq1.makederivs(n=grd1) 'step 1: regress test variable on derivs and get residsequation eq2.ls @trend grd1eq2.makeresids zres 'step 2: weight step 1 resids by restricted residsseries zu = zres*res 'step 3: run robust Gauss-Newton regression (11.69)eq2.ls 1 zu 'step 4: compute test statistic n*R^2_uscalar lmstat2 = eq2.@regobs - eq2.@ssr 'show results in tabletable outout(1,1) = "Omitted variable test based on heteroskedasticity robust Gauss-Newton regression:"out(2,1) = "n*R^2_u = "out(2,2) = lmstat2out(2,3) = "p-value = "out(2,4) = 1 - @cchisq(lmstat2,1) 'one-variable case can be computed by "regular" Gauss-Newton regression with White standard errorsequation eq2.ls(h) res @trend grd1show eq2.output 'robust t-statistic in test regression!tstat = eq2.@tstats(1)'degrees of freedom!df = eq2.@regobs - eq2.@ncoefout(3,1) = "robust t-stat = "out(3,2) = !tstatout(3,3) = "p-value = "out(3,4) = 2*(1-@ctdist(@abs(!tstat),!df))show out